package com.bbkb.quartz.remoting.impl;

import com.bbkb.common.exception.BaseException;
import com.bbkb.common.page.PageResult;
import com.bbkb.quartz.dto.SysJobDTO;
import com.bbkb.quartz.exception.QuartzException;
import com.bbkb.quartz.remoting.ISysJobRemoting;
import com.bbkb.quartz.service.ISysJobService;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author nobi
 */
@Service("sysJobRemoting")
public class SysJobRemotingImpl implements ISysJobRemoting {

    @Autowired
    private ISysJobService sysJobService;

    /**
     * 新增定时任务
     *
     * @param sysJobDTO
     */
    @Override
    public void addSysJob(SysJobDTO sysJobDTO) throws BaseException {
        if (Objects.isNull(sysJobDTO)) {
            throw new BaseException("定时任务对象不可为空");
        }
        sysJobService.addSysJob(sysJobDTO);
    }

    /**
     * 获取定时任务
     *
     * @param jobId 定时任务ID
     * @return
     * @throws QuartzException
     */
    @Override
    public SysJobDTO getSysJob(Long jobId) throws BaseException {
        SysJobDTO sysJobDTO = sysJobService.getSysJob(jobId);
        return sysJobDTO;
    }

    @Override
    public PageResult<SysJobDTO> queryPage(SysJobDTO jobDTO) throws BaseException {
        return sysJobService.queryPage(jobDTO);
    }

    @Override
    public void run(Long id) throws SchedulerException {
        sysJobService.run(id);
    }

}
